package com.glorysoft.xztpda.bindingadapter

import android.graphics.drawable.Drawable
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import android.widget.TextView
import androidx.databinding.BindingAdapter
import com.glorysoft.xztpda.entity.LotInfoEntity
import java.lang.NumberFormatException

/**
 * FileName: NumEditextAdapter
 * Author: XJH
 * Date: 2022/4/28 18:34
 * Description:
 * History:
 */
object NumEditextAdapter {

    @BindingAdapter(value = ["numEditMaterial"], requireAll = false)
    @JvmStatic
    fun setNumEditText(editText: EditText, material: LotInfoEntity.Material) {
        editText.addTextChangedListener(object : TextWatcher{
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {

            }

            override fun afterTextChanged(s: Editable?) {
                if (s.toString().isNotEmpty()) {
                    try {
                        material.consumemainqty =s.toString().toDouble()
                    }catch (e : NumberFormatException){
                        material.consumemainqty =0.0
                    }

                }

            }

        })
    }
}